import { ValidationPipe, ValidationError } from '@nestjs/common';

// 自定义处理错误数据 转换成自己想要的格式 可以在main.ts中调用
export default class Validate extends ValidationPipe {
  protected mapChildrenToValidationErrors(error: ValidationError, parentPath?: string): ValidationError[] {
    const errors = super.mapChildrenToValidationErrors(error, parentPath);
    errors.map((error) => {
      for (const key in error.constraints) {
        error.constraints[key] = error.property + '-' + error.constraints[key];
      }
    });

    return errors;
  }
}
